#include <cstdio>

using namespace std;

const int maxn=2200000;

namespace IO{
    const int sz=1<<22;
    char a[sz+5],b[sz+5],*p1=a,*p2=a,*t=b,p[105];
    inline char gc(){
        return p1==p2?(p2=(p1=a)+fread(a,1,sz,stdin),p1==p2?EOF:*p1++):*p1++;
    }
    template<class T> void gi(T& x){
        x=0; char c=gc();
        for(;c<'0'||c>'9';c=gc());
        for(;c>='0'&&c<='9';c=gc())
            x=x*10+(c-'0');
    }
    inline void flush(){fwrite(b,1,t-b,stdout),t=b; }
    inline void pc(char x){*t++=x; if(t-b==sz) flush(); }
    template<class T> void pi(T x,char c='\n'){
        if(x==0) pc('0'); int t=0;
        for(;x;x/=10) p[++t]=x%10+'0';
        for(;t;--t) pc(p[t]); pc(c);
    }
}
using IO::gi;
using IO::pi;

int n, son[maxn+1], bro[maxn+1], dfn[maxn+1], size[maxn+1];

void build(int o) {
    dfn[o] = ++dfn[0];
    size[o] = 1;
    for (int i=son[o]; i; i=bro[i]) {
        build(i);
        size[o] += size[i];
    }
}

int main() {
    freopen("ancestor.in", "r", stdin);
    freopen("ancestor.out", "w", stdout);

    gi(n);
    for (int i=2; i<=n; i++) {
        int x;
        gi(x);
        bro[i] = son[x];
        son[x] = i;
    }

    build(1);

    int fn=0;
    static int fas[maxn+1], ans[maxn+1];
    for (int i=1; i<=n; i++) {
        for (; fn && (dfn[i]<dfn[fas[fn]] || dfn[i]>=dfn[fas[fn]]+size[fas[fn]]); fn--);
        fas[++fn] = i;
        pi(fn);
    }
    if (IO::t!=IO::b) IO::flush();

    fclose(stdin);
    fclose(stdout);
    return 0;
}
